﻿@model IEnumerable<DNA.OpenAPI.OpenSearch.OpenSearchAtomResult>
@{
    Layout = LayoutSwitcher.GetMasterLayout();
}
<table style="width: 100%;">
    <tr>
        <td style="vertical-align: top;">
            @if (!string.IsNullOrEmpty(ViewBag.SearchTerms))
            {
                <h1>
                    @Html.Global("SearchResultFor") "@ViewBag.SearchTerms"</h1>
            }
            <div id="searchtabs" style="width: 650px;">
                <ul>
                    @{var i = 0;}
                    @foreach (var result in Model)
                    {
                        <li><a href="@("#tab" + result.ID)">@(result.Title + "\n\t(" + result.TotalResults.ToString() + ")")</a></li>
                    }
                </ul>
                @{i = 0;}
                @foreach (var result in Model)
                {
                    <div id="@("tab" + result.ID)">
                        @if (result.TotalResults > 0)
                        {
                            var entries = result.Entries;
                            foreach (var entry in entries)
                            { 
                            <h3 style="margin: 10px 0px 0px 0px; border: none;" class="d-post-title">
                                <a href="@entry.ID">@GE.GetContent(entry.Title)</a></h3>
                            <p style="margin: 0px; overflow: hidden;">@GE.GetContent(entry.Summary)</p>
                            <cite>@entry.ID</cite>
                            }
                            @(Ajax.Dna().Pager(result.ID + "pager")
                            .HtmlAttributes(new { style = "margin-top:10px;" })
                            .Options(opts =>
                            {
                                opts.PageIndex = result.StartIndex;
                                opts.PageSize = result.ItemsPerPage;
                                opts.TotalRecords = result.TotalResults;
                                opts.OnPageIndexChanged = "location=\"" + Url.Action("Search", new { terms = result.Query.SearchTerms, provider = result.ID }) + "&index=\"+ui.pageIndex+\"&size=\"+ui.pageSize+\"#tab" + result.ID + "\";";
                            })
                            .GetHtml())
                        }
                        else
                        {
                            <div style="padding: 20px;">
                                @Html.Global("NoSearchResult")</div>
                        }
                    </div>
                }
            </div>
        </td>
        <td style="width: 300px; vertical-align: top;">
            @Ajax.Dna().WidgetZone(Html.Global("RES_RIGHTZONE"), "zone1").GetHtml()
        </td>
    </tr>
</table>
<script type="text/javascript">
    $(function () {
        $("#searchtabs").tabs({ fx: { "opacity": "toggle", "width": "toggle"} });
    });
</script>
